package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 里
 * @Data:2022/01/03/0:20
 * @Description:
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //localhost/admin/product/baseTrademark/1/10
    // 获取品牌分页列表
    @GetMapping("/{page}/{size}")
    public Result getBaseTrademarkList(@PathVariable Long page,
                                       @PathVariable Long size){
        Page<BaseTrademark> pageParm = new Page<>(page, size);
        IPage<BaseTrademark> iPage =  baseTrademarkService.getBaseTrademarkList(pageParm);
        return Result.ok(iPage);
    }

    //http://localhost/admin/product/baseTrademark/save 品牌的新增
    @PostMapping("save")
    public Result save (@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }
    // 删除品牌
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    // 修改品牌 http://localhost/admin/product/baseTrademark/get/7
    // 1. 先获取数据再修改
    @GetMapping("/get/{id}")
    public Result getBaseTrademarkById(@PathVariable String id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @PutMapping("/update")
    public Result update (@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }



}
